<template>
	<view>
		<view style="margin: 40rpx 40rpx;">
			<text class="tetx">请输入旧密码</text>
			<view class="number">
				<input type="number" placeholder="请输入旧密码" v-model="passwordData.oldPasswords"  />
			</view>
			<text class="text">新密码</text>
			<view class="number">
				<input type="number" placeholder="请输入新密码" v-model="passwordData.newPasswords" />
			</view>
			<text class="text">确认密码</text>
			<view class="number">
				<input type="number" placeholder="请再次输入新密码" v-model="passwordData.confirmPasswords" />
			</view>
			
			
			<button style="margin-top: 40rpx; width: 670rpx;height: 88rpx; background-color: rgb(24, 119, 242)" @click="revisepassword ">确认</button>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { revisePasswordApi } from '../../../api/teamDoctor';
import { useUserStore } from '../../../store/user';
//状态机
const popupRef = ref(null)
	const open = () => {popupRef.value?.open()}
	const userStore = useUserStore()
const passwordData = ref({
	oldPasswords:"",
	newPasswords:"",
	confirmPasswords:""
})
function revisepassword (){
	if(passwordData.value.oldPasswords!=userStore.userInfo.password){
		uni.showToast({
			title: '旧密码不正确请确认后再输入',
			duration: 3000,
			icon: 'error'
		});
		passwordData.value.oldPasswords =""
	} else if(passwordData.value.newPasswords != passwordData.value.confirmPasswords){
		uni.showToast({
			title: '两次密码不一致请请确认后重新输入',
			duration: 3000,
			icon: 'error'
		});
		passwordData.value.newPasswords="",
		passwordData.value.confirmPasswords=""
		
	} else {
		revisePasswordApi({
			_id:userStore.userInfo._id,
			password:passwordData.value.confirmPasswords
		}).then(res=>{
			if(res.code == 200 ){
				uni.showToast({
					title: '修改成功',
					duration: 3000
				});
				uni.navigateBack(-1)
				userStore.getUserInfo()
			}
		})
	}
	
}


</script>

<style scoped lang="scss">
.number{
		display: flex;
		width: 670rpx;
		height: 88rpx;
		border: 1px solid rgb(242, 247, 251);
		border-radius: 10rpx;
		background-color: rgb(242, 247, 251);
		margin: auto;
		margin: 40rpx 0;
		line-height: 88rpx;
		input{
			height: 100%;
			line-height: 88rpx;
		}
	}      
	 .tetx{
		 margin: 20rpx 0;
		 font-size: 28rpx;
		 color:#333 ;
	 }
</style>
